const express = require('express');
const app = express();

app.use((request, response, next) => {
    console.log('请求服务器了');
    console.log('请求来自于', request.get('Host'));
    console.log('请求的地址是', request.url);
    next();
});

app.get('/students', (request, response) => {
    // response.setHeader('Access-Control-Allow-Origin', '*');
    const students = [
        { id: 001, name: 'tom', age: 18 },
        { id: 002, name: 'lily', age: 15 },
        { id: 003, name: 'nancy', age: 19 }
    ];
    response.send(students);
});

app.listen(8000, () => {
    console.log('服务已启动, 在8000端口监听, 地址"http://localhost:8000/students"');
})